﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_panel_Thongkechitiet : System.Web.UI.Page
{
    public static int flag = -1;
    public List<items> listnn = new List<items>();
    BieumauDataContext _db = new BieumauDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["login_admin"] == null)
        {
            Response.Redirect("Index.aspx");

        }
        if (!IsPostBack)
        {
            listnn = null;
            dropnam.Items.Clear();
            dropnam.Items.Add("Chọn một năm");
            for (int i = 2013; i <=Convert.ToInt32(DateTime.Now.Year.ToString()); i++)
            {
                dropnam.Items.Add(i.ToString());
            }
        }
    }
    
    protected void dropnam_SelectedIndexChanged1(object sender, EventArgs e)
    {
        int nam = Convert.ToInt32(dropnam.SelectedItem.ToString().Trim());
        if (dropnam.SelectedIndex != 0)
        {
            listnn.Clear();
            var result = from p in _db.tblBieuMaus
                         where p.NamBaoCao == nam & p.MaDonVi!="1"
                         group p by p.MaDonVi into g
                         select new { madv = g.Key };
            foreach (var g in result)
            {
                var item = (from p in _db.tblCoQuanNhaNuocs
                            where p.MaCoQuan.Trim() == g.madv.ToString().Trim()
                            select new items
                            {

                                MADV = p.MaCoQuan,
                                TENDV = p.TenCoQuan,
                                SDT = p.SDT,
                                EMAIL = p.email
                            });
                foreach (var i in item)
                {
                    items li = new items();
                    li.MADV = i.MADV;
                    li.TENDV = i.TENDV;
                    li.SDT = i.SDT;
                    li.EMAIL = i.EMAIL;
                    listnn.Add(li);
                }

            }
        }
        else
        {
            listnn = null;
        }

    }
}
public class items
{
    public string MADV { get; set; }
    public string TENDV { get; set; }
    public string SDT { get; set; }
    public string EMAIL { get; set; }
    public items()
    {
    }

}
